package com.gzsxy.config;

import com.gzsxy.utils.SessionUserUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

import java.util.Map;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 令牌存储策略
 * @date 2021/11/6 14:27
 */
@Configuration
public class TokenConfig {

    private String SIGNING_KEY = "uaa123";


    //令牌存储策略
    @Bean
    public TokenStore tokenStore(){
        //内存方式，生产普通令牌
        return new InMemoryTokenStore();
    }

//    //生成JWT令牌存储策略
//    @Bean
//    public  TokenStore tokenStore(){
//        //生成JWT令牌
//        return new JwtTokenStore(accessTokenConverter());
//    }

//    @Bean
//    public JwtAccessTokenConverter accessTokenConverter(){
//        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
//        //对称密钥，资源服务器使用该密钥来验证
//        converter.setSigningKey(SIGNING_KEY);
//        return converter;
//    }




    //设置密码加密模式
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }




    public static void main(String[] args) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String encode = encoder.encode("123456");
        System.out.println(encode);
    }
}
